package com.seeyon.ctp.portal.section;

import java.io.IOException;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.apache.commons.lang.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.seeyon.ctp.portal.section.BaseSectionImpl;
import com.seeyon.ctp.portal.section.templete.BaseSectionTemplete;
import com.seeyon.ctp.portal.section.templete.HtmlTemplete;

public class SecuritiesNewsSection extends BaseSectionImpl {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	}
	
	@Override
    public String getId() {
        //栏目ID，必须与spring配置文件中的ID相同;如果是原栏目改造，请尽量保持与原栏目ID一致
        return "securitiesNewsSection";
    }

    @Override
    public String getName(Map<String, String> preference) {
        //栏目显示的名字，必须实现国际化，在栏目属性的“columnsName”中存储
        String name = preference.get("columnsName");
        if(StringUtils.isBlank(name)){
            return "证券信息";
        }else{
            return name;
        }
    }

    @Override
    public Integer getTotal(Map<String, String> preference) {
        //栏目需要展现总数据条数时重写
        return null;
    }

    @Override
    public String getIcon() {
        // 栏目图标，暂不需要实现
        return null;
    }

    @Override
    public BaseSectionTemplete projection(Map<String, String> preference) {
        
        HtmlTemplete ht = new HtmlTemplete();
        StringBuilder html = new StringBuilder();
        if("".equals(crawlArticleList())) {
        	html.append("<div style=\"font-size: 20px;position: absolute;top: 50%;left: 50%;width:290px;height:23px;margin: -11px 0 0 -145px\">数据提供商维护，数据敬请期待!</div>");
        }
        ht.setHtml(html.toString());
        ht.setModel(HtmlTemplete.ModelType.inner);
        return ht;
    }
	
	public String crawlArticleList() {
		Document doc;
        StringBuffer sb = new StringBuffer("");
        try {
            doc = Jsoup.connect("http://www.chinamoney.com.cn/fe/jsp/CN/chinamoney/infoPublish/searchInfoPublishResult.jsp").timeout(5000).get();
        } catch (IOException e) {
        	sb.append("");
        }
        return sb.toString();
    }

	
}
